#include <bits/stdc++.h>
using namespace std;

int n, m, q, X1, X2, Y1, Y2;
char s[2005][2005];
int f[2005][2005];
int qu[4000001][2], front, rear;
const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
#define check(x, y) (x >= X1 && x <= X2 && y >= Y1 && y <= Y2)

void bfs(int x, int y, int c) {
	qu[front = rear = 1][0] = x;
	qu[1][1] = y;
	f[x][y] = c;
	while (rear + 1 != front) {
		int fx = qu[front][0], fy = qu[front][1]; ++front;
		for (int i = 0; i < 4; ++i) {
			int nx = fx + d[i][0], ny = fy + d[i][1];
			if (check(nx, ny) && f[nx][ny] == 0 && s[nx][ny] == '1') {
				f[nx][ny] = c;
				qu[++rear][0] = nx;
				qu[rear][1] = ny;
			}
		}
	}
}

int main() {
	freopen("unicom.in", "r", stdin);
	freopen("unicom.out", "w", stdout);
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
	}
	while (q--) {
		scanf("%d%d%d%d", &X1, &Y1, &X2, &Y2);
		int tot = 0;
		memset(f, 0, sizeof(f));
		for (int i = X1; i <= X2; ++i) {
			for (int j = Y1; j <= Y2; ++j) {
				if (f[i][j] == 0 && s[i][j] == '1') {
					++tot;
					bfs(i, j, tot);
				}
			}
		}
		printf("%d\n", tot);
	}
	return 0;
}
